//Copyright (c) Microsoft Corporation.  All rights reserved.

using System;
using System.Collections.Generic;
using System.Text;
using Eas.WebCrawler.Interfaces;

namespace Eas.WebCrawler.PlugIns.Selectors {

    /// <summary>A base class for selectors which contains an inner (nested) selector to which the derived class can delegate.</summary>
    public class DecoratingSelector : LinkSelector{

        private Eas.WebCrawler.Interfaces.LinkSelector _InnerSelector;

        /// <summary>Constructs a <see cref="DecoratingSelector"/> from an inner selector to which derived classes can delegate.</summary>
        /// <param name="innerSelector">An inner <see cref="LinkSelector"/> to which derived classes can delegate.</param>
        public DecoratingSelector(Eas.WebCrawler.Interfaces.LinkSelector innerSelector) { _InnerSelector = innerSelector; }

        /// <summary>An inner selector to which derived classes can delegate.</summary>
        public Eas.WebCrawler.Interfaces.LinkSelector InnerSelector {
            get { return _InnerSelector; }
        }

        #region LinkSelector Members

        /// <summary>Determines whether or not a <see cref="Request"/> (link) should be crawled.</summary>
        /// <param name="request">The request which has just been encountered.</param>
        /// <returns><code>true</code> if the request should be crawled, otherwise <code>false</code>.</returns>
        /// <remarks>This implementation just delegates to its <see cref="InnerSelector"/>.  This is not broadly useful and so derived classes will likely want to override this function.</remarks>
        public virtual bool ShouldFollow(Eas.WebCrawler.Interfaces.Request request) {
            return _InnerSelector.ShouldFollow(request);
        }

        #endregion

        #region WebCrawlerComponent Members
        /// <summary>Initializes this class</summary>
        /// <param name="context">The <see cref="WebCrawlerContext"/> which will contain data about this instance of the web crawler.</param>
        public void Initialize(Eas.WebCrawler.Interfaces.WebCrawlerContext context) {
            _InnerSelector.Initialize(context);
        }
        #endregion
    }
}
